// pages/student2/confirm/confirm.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    comment: "",
    focus:false,
    array1: [0, 1, 2, 3, 4, 5],
    array2: [0, 1, 2, 3, 4, 5],
    array3: [0, 1, 2, 3, 4, 5],
    index1: 5,
    index2: 5,
    index3: 5,
    loadingHidden: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id,
      s_id: options.s_id,
      w_id: options.w_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  bindInputChange: function(e) {
    this.setData({
      comment: e.detail.value,
      focus:false
    })
  },
  bindPickerChange1: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index1: e.detail.value
    })
  },
  bindPickerChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index2: e.detail.value
    })
  },
  bindPickerChange3: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index3: e.detail.value
    })
    console.log(this.data.focus)
  },
  submit: function(e) {
    console.log(this.data.id)
    console.log(this.data.s_id)
    console.log(this.data.w_id)
    console.log(this.data.comment)
    console.log(this.data.index1)
    console.log(this.data.index2)
    console.log(this.data.index3)
    if (this.data.comment === "") {
      wx.showToast({
        title: '请输入维修评价',
        icon: "none"
      })
    } else {
      this.setData({
        loadingHidden: false
      })
      var that = this
      wx.request({
        url: app.globalData.BASE_URL + '/order/studentUpdateOrder',
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
        },
        data: {
          token: app.globalData.token,
          userType: app.globalData.userType,
          id: that.data.id,
          s_id: that.data.s_id,
          w_id: that.data.w_id,
          comment: that.data.comment,
          score1: that.data.index1,
          score2: that.data.index2,
          score3: that.data.index3,
        },
        success(res) {
          that.setData({
            loadingHidden: true
          })
          console.log(res)
          if (res.data === 1) {
            wx.showToast({
              title: '确认成功',
            })
            wx.redirectTo({
              url: '/pages/student2/maintaining/maintaining',
            })
          } else if (res.data === 2) {
            wx.showToast({
              title: '确认失败',
              icon: "none",
            })
          } else if (res.data === 444) {
            app.globalData.status = null
            app.globalData.token = null
            app.globalData.user = null
            app.globalData.userType = null
            wx.navigateTo({
              url: '/pages/login/index?flag=invalid',
            })
          }
        }
      })
    }
  },
  goInput:function(){
    console.log("hhh")
    this.setData({
      focus:true
    })
  }
})